//
//  NSMutableDictionary+UrlGenerate.m
//  podrow
//
//  Created by Michael Xu on 4/25/14.
//  Copyright (c) 2014 podrow. All rights reserved.
//

// helper function: get the url encoded string form of any object
static NSString *urlEncode(id object)
{
    NSString *string = [object description];
    return [string stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
}

#import "NSMutableDictionary+UrlGenerate.h"

@implementation NSMutableDictionary (UrlGenerate)

- (NSString*) urlEncodedString
{
    NSMutableArray *parts = [NSMutableArray array];
    for (id key in self) {
        id value = [self objectForKey: key];
        NSString *part = [NSString stringWithFormat: @"%@=%@", urlEncode(key), urlEncode(value)];
        [parts addObject: part];
    }
    return [parts componentsJoinedByString: @"&"];
}

@end
